<template>
    <div>

        <h1>科室信息录入</h1>
         <a href="/">科室信息显示</a>
        <table class="table">
             <tbody>
                <tr>
                    <td>科室名称</td>
                    <td>
                        <input type="text" v-model="data.ksName">
                    </td>
                </tr>
                <tr>
                    <td>科室人数</td>
                    <td>
                        <input type="number" v-model="data.kScount">
                    </td>
                </tr>
                <tr>
                    <td>科室描述</td>
                    <td>
                        <textarea v-model="data.ksms"> 
                        </textarea>
                    </td>
                </tr>
                <tr>
                    <td>创建日期</td>
                    <td>
                        <input type="date" v-model="data.ksDate">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="添加" @click="add"> 
                    </td>
                </tr>
             </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router=useRouter();
const data =ref({
  "id": 0,
  "ksName": "",
  "kScount": 0,
  "ksms": "",
  "ksDate": "2025-05-19T02:29:27.161Z",
  "isDelete": true
})

const add =()=>{
    axios.post("/api/HouseKS/AddHouseKS",data.value).then(res=>{
        if(res.data>0)
    {
        alert("科室信息添加成功");
       router.push({path:"/showks"})
    }
    if(res.data==-1)
    {
          alert("科室信息名称重复")
          return;
    }
    if(res.data<0)
    {
     alert("科室信息添加失败");
     return;
    }
    })
}

</script>

<style scoped>

</style>